import {V,Connection} from "e:/mjwork/x-engine";
import {X} from "e:/mjwork/xorm";
import { User } from '../model/user';
import { UUID, success, failed, GetCache, SetCache } from '../utils';
@V.Controller({
    type : Connection.HTTP,
    url : "/account/:method",
    dataType:"json"
})
export class AccountController{


    /**
     * 登录游客用户
     */
    async login_visitor(){
        //生成新用户
        let user = new User;
        user.name = 'guest_' + UUID();
        user.nickname = user.name;
        user.token = UUID();
        await X.save(user);
        if(user.id){
            delete user.password;
            return success(user)
        }
        return failed(-1,"登录失败");
    }


    /**
     * 暴露用户信息
     */
    async get_user_info(user_id : number){
        let user = await X.of(User).findOne(user_id);
        if(!user){
            return failed();
        }
        //禁止暴露密码和token
        delete user.password;
        delete user.token;
        return success(user);
    }

    


}